/**
 * Created by ㅋㅋElsa on 2017/8/22.
 */
layui.define(['jquery', 'layer','paging', 'code','form','element'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var inspnum = getQueryString("inspnum");

    var therole = "";
    $.ajax({
        type:"GET",
        url:contextPath+"/personal/role",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            therole = data.role;
            if(data.role=="管理员"||data.role=="船厂"){
                $('#add').show();
            }
        },
        error: function (e) {
        }
    });

    paging.init({
        url: contextPath + "/project/const/inspdclr/" + inspnum, //地址
        elem: '#con', //内容容器
        type: 'GET',
        //new
        key: '#s_type',
        value: '#s_value',
        params: { //发送到服务端的参数
        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
            if(therole == "管理员"){
                $('.moress').show();
                $('.deletee').show();
            }else if(therole == "负责人"){
                $('.moress').show();
            }else if(therole == "验船师"){
                $('.moress').show();
                $('.mores2').show();
                $('.mores3').show();
            }else if(therole == "船厂"){
                $('.moress').show();
                $('.mores4').show();
                $('.mores4').click();
            }else if(therole == "船东"){
                $('.moress').show();
                $('.mores1').show();
                $('.mores4').show();
                $('.mores4').click();
            }else{

            }
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调
        },
    });

    $("body").on("click",".mores4",function(){
        var inspdate = $(this).data('id');
        var xx = false;

        $.ajax({
            type:"GET",
            async: false,
            url:contextPath+"/project/const/inspdclr/info",
            data: {"inspnum": inspnum, "inspdate": inspdate},
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function (data) {
                if(therole == "船厂"){
                    if(data.idstate == "需要整改"&&data.ccopn==""){
                        xx = true;
                    }
                }else if(therole == "船东"){
                    if(data.idstate == "需要整改"&&data.cdopn==""){
                        xx = true;
                    }
                }else{

                }
            },
            error: function (e) {
            }
        });

        if(xx){
            $(this).attr('class','layui-btn layui-btn-normal layui-btn-mini mores5');
        }

    });

    $("body").on("click",".mores1",function(){
        var inspdate = $(this).data('id');
        tampdata = $(this).data('id');

        $.ajax({
            type:"GET",
            url:contextPath+"/project/const/inspdclr/info",
            data: {"inspnum": inspnum, "inspdate": inspdate},
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function (data) {
                if(!data.cdopinion){
                    $.get('ConstCdReview.html', null, function(ConstCdReview) {
                        index = layer.open({
                            type: 1,
                            title: '报检单-船东审核',
                            content: ConstCdReview,
                            area: ['auto', '600px'],
                            maxmin: false,
                            success:function (layero,index) {
                                layero.find("#closex").on("click",function () {
                                    layer.closeAll();
                                });
                        
                                $('input[name="shipname"]').attr("value",data.shipname);
                                $('input[name="figurenum"]').attr("value",data.figurenum);
                                $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                $('input[name="apnttime"]').attr("value",data.apnttime);
                                $('input[name="inspname"]').attr("value",data.inspname);
                                $('textarea[name="insppro"]').val(data.insppro);
                                $('input[name="cc"]').attr("value",data.cc);
                                $('input[name="rq1"]').attr("value",data.rq1);

                                $.ajax({
                                    type: "GET",
                                    url: contextPath + "/personal/info",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (data) {
                                        $('input[name="cd"]').attr("value",data.name);
                                    },
                                    error: function (e) {

                                    }
                                });
                                $('input[name="rq2"]').attr("value",getNowFormatDate());
                            },
                            yes: function(index) {
                                console.log(index);
                            },
                            full: function(elem) {
                                var win = window.top === window.self ? window : parent.window;
                                $(win).on('resize', function() {
                                    var $this = $(this);
                                    elem.width($this.width()).height($this.height()).css({
                                        top: 0,
                                        left: 0
                                    });
                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                });
                            }
                        });
                        form.render();
                    });
                }else {
                    layer.msg('船东已审核<br>'+data.cdopinion , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error: function (e) {
            }
        });
    });

    $("body").on("click",".mores2",function(){
        var inspdate = $(this).data('id');
        tampdata = $(this).data('id');

        $.ajax({
            type:"GET",
            url:contextPath+"/project/const/inspdclr/info",
            data: {"inspnum": inspnum, "inspdate": inspdate},
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function (data) {
                if(!data.cdopinion){
                    layer.msg('报检单<br>船东未审核' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else if(data.cdopinion=="不通过"){
                    layer.msg('报检单<br>船东审核未通过' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else if(!data.status){
                    $.get('ConstYcsConfirm.html', null, function(ConstYcsConfirm) {
                        index = layer.open({
                            type: 1,
                            title: '报检单-验船师确认',
                            content: ConstYcsConfirm,
                            area: ['auto', '600px'],
                            maxmin: false,
                            success:function (layero,index) {
                                layero.find("#closex").on("click",function () {
                                    layer.closeAll();
                                });

                                $('input[name="shipname"]').attr("value",data.shipname);
                                $('input[name="figurenum"]').attr("value",data.figurenum);
                                $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                $('input[name="apnttime"]').attr("value",data.apnttime);
                                $('input[name="inspname"]').attr("value",data.inspname);
                                $('textarea[name="insppro"]').val(data.insppro);
                                $('input[name="cc"]').attr("value",data.cc);
                                $('input[name="rq1"]').attr("value",data.rq1);
                                $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                $('input[name="cd"]').attr("value",data.cd);
                                $('input[name="rq2"]').attr("value",data.rq2);

                                $.ajax({
                                    type: "GET",
                                    url: contextPath + "/personal/info",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (data) {
                                        $('input[name="ycs1"]').attr("value",data.name);
                                    },
                                    error: function (e) {

                                    }
                                });
                                $('input[name="rq3"]').attr("value",getNowFormatDate());
                            },
                            yes: function(index) {
                                console.log(index);
                            },
                            full: function(elem) {
                                var win = window.top === window.self ? window : parent.window;
                                $(win).on('resize', function() {
                                    var $this = $(this);
                                    elem.width($this.width()).height($this.height()).css({
                                        top: 0,
                                        left: 0
                                    });
                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                });
                            }
                        });
                        form.render();
                    });
                }else {
                    layer.msg('验船师已确认<br>'+data.status , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error:function (e) {
            }
        });        
    });


    $("body").on("click",".mores5",function(){
        var inspdate = $(this).data('id');
        tampdata = $(this).data('id');

        $.ajax({
            type:"GET",
            url:contextPath+"/project/const/inspdclr/info",
            data: {"inspnum": inspnum, "inspdate": inspdate},
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function (data) {
                if(therole=="验船师"){
                    if(!data.status){
                        layer.msg('报检单验船师未确认', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.status=="报检单填写有误"){
                        layer.msg('报检单填写有误', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="通过") {
                        layer.msg('验船师已审核<br>'+data.inspopinion , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"&&data.confirmresult=="完成"){
                        layer.msg('报检单整改完成', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"||(!data.inspopinion&&data.status=="报检单填写无误")){
                        $.get('ConstYcsReview.html', null, function(ConstYcsReview) {
                            index = layer.open({
                                type: 1,
                                title: '报检单-验船师审核',
                                content: ConstYcsReview,
                                area: ['auto', '600px'],
                                maxmin: false,
                                success:function (layero,index) {
                                    layero.find("#closex").on("click",function () {
                                        layer.closeAll();
                                    });

                                    $('#confrimlabel').html("确认检验日期");
                                    $('input[name="confirmtime"]').show();

                                    if(data.inspopinion=="需整改"){
                                        $('#rectnumlabel').html("整改编号");
                                        $('input[name="rectnum"]').show();
                                        form.render();
                                    }
                                    
                                    $('input[name="shipname"]').attr("value",data.shipname);
                                    $('input[name="figurenum"]').attr("value",data.figurenum);
                                    $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                    $('input[name="apnttime"]').attr("value",data.apnttime);
                                    $('input[name="inspname"]').attr("value",data.inspname);
                                    $('textarea[name="insppro"]').val(data.insppro);
                                    $('input[name="cc"]').attr("value",data.cc);
                                    $('input[name="rq1"]').attr("value",data.rq1);
                                    $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                    $('input[name="cd"]').attr("value",data.cd);
                                    $('input[name="rq2"]').attr("value",data.rq2);
                                    $('input[name="status"]').attr("value",data.status);
                                    $('input[name="confirmtime"]').attr("value",data.confirmtime);
                                    $('input[name="ycs1"]').attr("value",data.ycs1);
                                    $('input[name="rq3"]').attr("value",data.rq3);
                                    if(data.inspopinion=="需整改"){
                                        $('#ccopn1').hide()
                                        $('#ccopn2').show()
                                        $('#cdopn1').hide()
                                        $('#cdopn2').show()
                                        if(data.ccopn){
                                            $('input[name="ccopn"]').attr("value",data.ccopn);
                                            $('input[name="ccopndate"]').attr("value",data.ccopndate);
                                        }
                                        if(data.cdopn){
                                            $('input[name="cdopn"]').attr("value",data.cdopn);
                                            $('input[name="cdopndate"]').attr("value",data.cdopndate);
                                        }
                                        $('select[name="inspopinion"]').val(data.inspopinion);
                                        $('#rectnum').show();
                                        $('#rect').show();
                                        $('#rectt').show();
                                        $('input[name="rectnum"]').attr("value",data.rectnum);
                                        $('input[name="ycs2"]').attr("value",data.ycs2);
                                        $('input[name="rq4"]').attr("value",data.rq4);
                                        $('select[name="confirmresult"]').val(data.confirmresult);
                                        $('textarea[name="rectopinion"]').val(data.rectopinion);
                                        $('textarea[name="rectresult"]').val(data.rectresult);
                                        $.ajax({
                                            type: "GET",
                                            url: contextPath + "/personal/info",
                                            contentType: "application/json; charset=utf-8",
                                            dataType: "json",
                                            success: function (data) {
                                                $('input[name="ycs3"]').attr("value",data.name);
                                            },
                                            error: function (e) {

                                            }
                                        });
                                        $('input[name="rq5"]').attr("value",getNowFormatDate());
                                    }else{
                                        $.ajax({
                                            type: "GET",
                                            url: contextPath + "/personal/info",
                                            contentType: "application/json; charset=utf-8",
                                            dataType: "json",
                                            success: function (data) {
                                                $('input[name="ycs2"]').attr("value",data.name);
                                            },
                                            error: function (e) {

                                            }
                                        });
                                        $('input[name="rq4"]').attr("value",getNowFormatDate());
                                    }

                                },
                                yes: function(index) {
                                    console.log(index);
                                },
                                full: function(elem) {
                                    var win = window.top === window.self ? window : parent.window;
                                    $(win).on('resize', function() {
                                        var $this = $(this);
                                        elem.width($this.width()).height($this.height()).css({
                                            top: 0,
                                            left: 0
                                        });
                                        elem.children('div.layui-layer-content').height($this.height() - 95);
                                    });
                                }
                            });
                            form.render();
                        });
                    }else{

                    }
                }else if(therole=="船厂"){
                    if(data.status=="报检单填写有误"){
                        layer.msg('报检单填写有误', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(!data.inspopinion){
                        layer.msg('验船师未审核<br>'+data.inspopinion , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="通过") {
                        layer.msg('验船师已审核<br>'+data.inspopinion , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.ccopn) {
                        layer.msg('船厂意见已填写' , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"&&data.confirmresult=="完成"){
                        layer.msg('报检单整改完成', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"){
                        $.get('ConstYcsReview.html', null, function(ConstYcsReview) {
                            index = layer.open({
                                type: 1,
                                title: '报检单-验船师审核',
                                content: ConstYcsReview,
                                area: ['auto', '600px'],
                                maxmin: false,
                                success:function (layero,index) {
                                    console.log("船厂...")
                                    layero.find("#closex").on("click",function () {
                                        layer.closeAll();
                                    });
                                    
                                    $('#confrimlabel').html("确认检验日期");
                                    $('input[name="confirmtime"]').show();
                                    $('#rectnumlabel').html("整改编号");
                                    $('input[name="rectnum"]').show();
                                    form.render();

                                    $('input[name="shipname"]').attr("value",data.shipname);
                                    $('input[name="figurenum"]').attr("value",data.figurenum);
                                    $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                    $('input[name="apnttime"]').attr("value",data.apnttime);
                                    $('input[name="inspname"]').attr("value",data.inspname);
                                    $('textarea[name="insppro"]').val(data.insppro);
                                    $('input[name="cc"]').attr("value",data.cc);
                                    $('input[name="rq1"]').attr("value",data.rq1);
                                    $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                    $('input[name="cd"]').attr("value",data.cd);
                                    $('input[name="rq2"]').attr("value",data.rq2);
                                    $('input[name="status"]').attr("value",data.status);
                                    $('input[name="confirmtime"]').attr("value",data.confirmtime);
                                    $('input[name="ycs1"]').attr("value",data.ycs1);
                                    $('input[name="rq3"]').attr("value",data.rq3);
                                    $('input[name="ccopndate"]').attr("value",getNowFormatDate());

                                    $('#inspopinion1').hide();
                                    $('#inspopinion2').show();
                                    $('#confirmresult1').hide();
                                    $('#confirmresult2').show();
                                    $('#cdopn1').hide();
                                    $('#cdopn2').show();
                                    $('#ccopn1').show();
                                    $('#ccopn2').hide();
                                    $('#rectnum').show();
                                    $('#rect').show();
                                    $('#rectt').show();
                                    $('input[name="rectnum"]').attr("disabled",true).attr("class","layui-input layui-disabled");
                                    $('textarea[name="rectopinion"]').attr("disabled",true).attr("class","layui-textarea layui-disabled");
                                    $('textarea[name="rectresult"]').attr("disabled",true).attr("class","layui-textarea layui-disabled");

                                    $('input[name="inspopinion"]').attr("value",data.inspopinion);
                                    $('input[name="confirmresult"]').attr("value",data.confirmresult);
                                    $('input[name="rectnum"]').attr("value",data.rectnum);
                                    $('input[name="ycs2"]').attr("value",data.ycs2);
                                    $('input[name="rq4"]').attr("value",data.rq4);
                                    $('input[name="ycs3"]').attr("value",data.ycs3);
                                    $('input[name="rq5"]').attr("value",data.rq5);
                                    $('textarea[name="rectopinion"]').val(data.rectopinion);
                                    $('textarea[name="rectresult"]').val(data.rectresult);

                                    if(data.cdopn){
                                        $('input[name="cdopn"]').attr("value",data.cdopn);
                                        $('input[name="cdopndate"]').attr("value",data.cdopndate);
                                    }

                                },
                                yes: function(index) {
                                    console.log(index);
                                },
                                full: function(elem) {
                                    var win = window.top === window.self ? window : parent.window;
                                    $(win).on('resize', function() {
                                        var $this = $(this);
                                        elem.width($this.width()).height($this.height()).css({
                                            top: 0,
                                            left: 0
                                        });
                                        elem.children('div.layui-layer-content').height($this.height() - 95);
                                    });
                                }
                            });
                            form.render();
                        });
                    }else{

                    }

                }else if(therole=="船东"){
                    if(data.status=="报检单填写有误"){
                        layer.msg('报检单填写有误', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(!data.inspopinion){
                        layer.msg('验船师未审核<br>'+data.inspopinion , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="通过") {
                        layer.msg('验船师已审核<br>'+data.inspopinion , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.cdopn) {
                        layer.msg('船东意见已填写' , {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"&&data.confirmresult=="完成"){
                        layer.msg('报检单整改完成', {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }else if(data.inspopinion=="需整改"){
                        $.get('ConstYcsReview.html', null, function(ConstYcsReview) {
                            index = layer.open({
                                type: 1,
                                title: '报检单-验船师审核',
                                content: ConstYcsReview,
                                area: ['auto', '600px'],
                                maxmin: false,
                                success:function (layero,index) {
                                    layero.find("#closex").on("click",function () {
                                        layer.closeAll();
                                    });
                                    console.log("船东...")
                                    
                                    $('#confrimlabel').html("确认检验日期");
                                    $('input[name="confirmtime"]').show();
                                    $('#rectnumlabel').html("整改编号");
                                    $('input[name="rectnum"]').show();
                                    form.render();

                                    $('input[name="shipname"]').attr("value",data.shipname);
                                    $('input[name="figurenum"]').attr("value",data.figurenum);
                                    $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                    $('input[name="apnttime"]').attr("value",data.apnttime);
                                    $('input[name="inspname"]').attr("value",data.inspname);
                                    $('textarea[name="insppro"]').val(data.insppro);
                                    $('input[name="cc"]').attr("value",data.cc);
                                    $('input[name="rq1"]').attr("value",data.rq1);
                                    $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                    $('input[name="cd"]').attr("value",data.cd);
                                    $('input[name="rq2"]').attr("value",data.rq2);
                                    $('input[name="status"]').attr("value",data.status);
                                    $('input[name="confirmtime"]').attr("value",data.confirmtime);
                                    $('input[name="ycs1"]').attr("value",data.ycs1);
                                    $('input[name="rq3"]').attr("value",data.rq3);
                                    $('input[name="cdopndate"]').attr("value",getNowFormatDate());

                                    $('#inspopinion1').hide();
                                    $('#inspopinion2').show();
                                    $('#confirmresult1').hide();
                                    $('#confirmresult2').show();
                                    $('#ccopn1').hide();
                                    $('#ccopn2').show();
                                    $('#cdopn1').show();
                                    $('#cdopn2').hide();
                                    $('#rectnum').show();
                                    $('#rect').show();
                                    $('#rectt').show();
                                    $('input[name="rectnum"]').attr("disabled",true).attr("class","layui-input layui-disabled");
                                    $('textarea[name="rectopinion"]').attr("disabled",true).attr("class","layui-textarea layui-disabled");
                                    $('textarea[name="rectresult"]').attr("disabled",true).attr("class","layui-textarea layui-disabled");

                                    $('input[name="inspopinion"]').attr("value",data.inspopinion);
                                    $('input[name="confirmresult"]').attr("value",data.confirmresult);
                                    $('input[name="rectnum"]').attr("value",data.rectnum);
                                    $('input[name="ycs2"]').attr("value",data.ycs2);
                                    $('input[name="rq4"]').attr("value",data.rq4);
                                    $('input[name="ycs3"]').attr("value",data.ycs3);
                                    $('input[name="rq5"]').attr("value",data.rq5);
                                    $('textarea[name="rectopinion"]').val(data.rectopinion);
                                    $('textarea[name="rectresult"]').val(data.rectresult);

                                    if(data.ccopn){
                                        $('input[name="ccopn"]').attr("value",data.ccopn);
                                        $('input[name="ccopndate"]').attr("value",data.ccopndate);
                                    }
                            
                                },
                                yes: function(index) {
                                    console.log(index);
                                },
                                full: function(elem) {
                                    var win = window.top === window.self ? window : parent.window;
                                    $(win).on('resize', function() {
                                        var $this = $(this);
                                        elem.width($this.width()).height($this.height()).css({
                                            top: 0,
                                            left: 0
                                        });
                                        elem.children('div.layui-layer-content').height($this.height() - 95);
                                    });
                                }
                            });
                            form.render();
                        });
                    }else{

                    }
                }else{

                }
            },
            error:function (e) {
            }
        });
    });

    $("body").on("click",".deletee",function(){
        var inspdate = $(this).data('id');
        layer.alert('是否删除该报检单?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/const/inspdclr/delete?inspnum="+inspnum+"&inspdate="+inspdate,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    if(data.message == "删除报检单成功!"){
                        layer.msg('删除成功!<br>页面将在1秒后刷新...', {
                            time: 1000 //1s后自动关闭
                        });
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".moress",function(){
        var inspdate = $(this).data('id');
        tampdata = $(this).data('id');

        $.get('ConstDetailsCheck.html', null, function(ConstDetailsCheck) {
            layer.open({
                type: 1,
                title: '报检单详情',
                content: ConstDetailsCheck,
                area: ['auto', '600px'],
                maxmin: false,
                success:function (layero,index) {
                    
                    layero.find("#closex").on("click",function () {
                        layer.closeAll();
                    });
                    layero.find("#closes").on("click",function () {
                        layer.closeAll();
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/const/inspdclr/info",
                        data: {"inspnum": inspnum, "inspdate": inspdate},
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            console.log(data);

                            if(data.status == "报检单填写无误"){
                                $('#confrimlabel').html("确认检验日期");
                                $('input[name="confirmtime"]').show();
                            }else{
                                $('#confrimlabel').html("");
                                $('input[name="confirmtime"]').hide();
                            }

                            if(data.inspopinion == "通过"){
                                $('#rectnum').html("");
                                $('input[name="rectnum"]').hide();
                                $('#norect').show();
                                $('#rect').hide();
                            }else if(data.inspopinion == "需整改"){
                                $('#rectnumlabel').html("整改编号");
                                $('input[name="rectnum"]').show();
                                $('#norect').hide();
                                $('#rect').show();
                            }else{

                            }
                            
                            $('input[name="shipname"]').attr("value",data.shipname);
                            $('input[name="figurenum"]').attr("value",data.figurenum);
                            $('input[name="ccpronum"]').attr("value",data.ccpronum);
                            $('input[name="apnttime"]').attr("value",data.apnttime);
                            $('input[name="inspname"]').attr("value",data.inspname);
                            $('textarea[name="insppro"]').val(data.insppro);
                            $('input[name="cc"]').attr("value",data.cc);
                            $('input[name="rq1"]').attr("value",data.rq1);
                            if(data.cdopinion){
                                console.log("船东审核");
                                $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                $('select[name="cdopinion"]').val(data.cdopinion);
                                $('input[name="cd"]').attr("value",data.cd);
                                $('input[name="rq2"]').attr("value",data.rq2);
                            }
                            if(data.status){
                                console.log("验船师确认");
                                $('input[name="status"]').attr("value",data.status);
                                $('select[name="status"]').val(data.status);
                                $('input[name="confirmtime"]').attr("value",data.confirmtime);
                                $('input[name="ycs1"]').attr("value",data.ycs1);
                                $('input[name="rq3"]').attr("value",data.rq3);
                            }
                            if(data.inspopinion){
                                console.log("验船师审核");
                                $('input[name="inspopinion"]').attr("value",data.inspopinion);
                                $('select[name="inspopinion"]').val(data.inspopinion);
                                $('input[name="ycs2"]').attr("value",data.ycs2);
                                $('input[name="rq4"]').attr("value",data.rq4);
                                if(data.inspopinion=="通过"){
                                    $('textarea[name="opncontent"]').val(data.opncontent);
                                }else if(data.inspopinion=="需整改"){
                                    $('input[name="rectnum"]').attr("value",data.rectnum);
                                    if(data.confirmresult=="未完成"||data.confirmresult=="完成"){
                                        $('select[name="confirmresult"]').val(data.confirmresult);
                                        $('input[name="confirmresult"]').attr("value",data.confirmresult);
                                    }
                                    $('input[name="ycs3"]').attr("value",data.ycs3);
                                    $('input[name="rq5"]').attr("value",data.rq5);
                                    $('textarea[name="rectopinion"]').val(data.rectopinion);
                                    $('textarea[name="rectresult"]').val(data.rectresult);
                                }else{
                                }
                                if(data.cdopn){
                                    $('input[name="cdopn"]').attr("value",data.cdopn);
                                    $('input[name="cdopndate"]').attr("value",data.cdopndate);
                                }
                                if(data.ccopn){
                                    $('input[name="ccopn"]').attr("value",data.ccopn);
                                    $('input[name="ccopndate"]').attr("value",data.ccopndate);
                                }
                            }
                            form.render();

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/personal/role",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    if(data.role!="管理员"){
                                        $('#edit').hide();
                                    }
                                },
                                error: function (e) {

                                }
                            });

                            $.ajax({
                                type: "GET",
                                url: contextPath + "/project/const/" + inspnum,
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    if(data.state=="禁用"){
                                        $('#edit').hide();
                                    }
                                },
                                error: function (e) {
                                }
                            });

                            $('#su').on('click',function () {
                                window.open('../../../print/const/ConstInspdclr/ConstInspdclr.html?inspnum='+inspnum+'&inspdate='+inspdate);
                            });

                            if(data.rectnum){
                                $('#sus').show();
                                $('#sus').on('click',function () {
                                    window.open('../../../print/const/ConstQualityTable/ConstQualityTable.html?inspnum='+inspnum+'&inspdate='+inspdate);
                                });
                            }

                            $('#edit').on('click',function () {
                                $('#xxx').hide();
                                $('#sss').show();
                                $('#cdopinion1').hide();
                                $('#cdopinion2').show();
                                $('#status1').hide();
                                $('#status2').show();
                                $('#inspopinion1').hide();
                                $('#inspopinion2').show();
                                $('#confirmresult1').hide();
                                $('#confirmresult2').show();

                                $('input[name="apnttime"]').attr('disabled', false);
                                $('input[name="inspname"]').attr('disabled', false);
                                $('textarea[name="insppro"]').attr('disabled', false);
                                $('input[name="cc"]').attr('disabled', false);
                                $('input[name="cdopinion"]').attr('disabled', false);
                                $('input[name="cd"]').attr('disabled', false);
                                $('input[name="status"]').attr('disabled', false);
                                $('input[name="confirmtime"]').attr('disabled', false);
                                $('input[name="ycs1"]').attr('disabled', false);
                                $('input[name="inspopinion"]').attr('disabled', false);
                                $('input[name="rectnum"]').attr('disabled', false);
                                $('input[name="ycs2"]').attr('disabled', false);
                                $('input[name="ycs3"]').attr('disabled', false);
                                $('textarea[name="opncontent"]').attr('disabled', false);
                                $('textarea[name="rectopinion"]').attr('disabled', false);
                                $('textarea[name="rectresult"]').attr('disabled', false);

                                $('input[name="apnttime"]').attr('class', 'layui-input');
                                $('input[name="inspname"]').attr('class', 'layui-input');
                                $('textarea[name="insppro"]').attr('class', 'layui-textarea');
                                $('input[name="cc"]').attr('class', 'layui-input');
                                $('input[name="cdopinion"]').attr('class', 'layui-input');
                                $('input[name="cd"]').attr('class', 'layui-input');
                                $('input[name="status"]').attr('class', 'layui-input');
                                $('input[name="confirmtime"]').attr('class', 'layui-input');
                                $('input[name="ycs1"]').attr('class', 'layui-input');
                                $('input[name="inspopinion"]').attr('class', 'layui-input');
                                $('input[name="rectnum"]').attr('class', 'layui-input');
                                $('input[name="ycs2"]').attr('class', 'layui-input');
                                $('input[name="ycs3"]').attr('class', 'layui-input');
                                $('textarea[name="opncontent"]').attr('class', 'layui-textarea');
                                $('textarea[name="rectopinion"]').attr('class', 'layui-textarea');
                                $('textarea[name="rectresult"]').attr('class', 'layui-textarea');
                            });

                            $('#submit').on('click',function () {
                                var ss1 = new Object();
                                var message1="", message2="", message3="", message4="";
                                ss1.inspnum = inspnum;
                                ss1.inspdate = inspdate;
                                ss1.apnttime = $('input[name="apnttime"]').val();
                                ss1.inspname = $('input[name="inspname"]').val();
                                ss1.insppro = $('textarea[name="insppro"]').val();
                                ss1.cc = $('input[name="cc"]').val();

                                $.ajax({
                                    type:"PUT",
                                    url:contextPath+"/project/const/inspdclr/update/cc",
                                    async: false,
                                    contentType: "application/json; charset=utf-8",
                                    data:JSON.stringify(ss1),
                                    dataType:"json",
                                    success:function (data) {
                                        message1 = data.message;
                                    },
                                    error:function (e) {
                                    }
                                });

                                if($('select[name="cdopinion"] option:selected').val()!=""){
                                    var ss2 = new Object();
                                    ss2.inspnum = inspnum;
                                    ss2.inspdate = inspdate;
                                    ss2.cdopinion = $('select[name="cdopinion"] option:selected').val();
                                    ss2.cd = $('input[name="cd"]').val();

                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/const/inspdclr/update/cd",
                                        async: false,
                                        contentType: "application/json; charset=utf-8",
                                        data:JSON.stringify(ss2),
                                        dataType:"json",
                                        success:function (data) {
                                            message2 = data.message;
                                        },
                                        error:function (e) {
                                        }
                                    });
                                }

                                if($('select[name="cdopinion"] option:selected').val()!=""&&$('select[name="status"] option:selected').val()!=""){
                                    var ss3 = new Object();
                                    ss3.inspnum = inspnum;
                                    ss3.inspdate = inspdate;
                                    ss3.status = $('select[name="status"] option:selected').val();
                                    ss3.confirmtime = $('input[name="confirmtime"]').val();
                                    ss3.ycs1 = $('input[name="ycs1"]').val();

                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/const/inspdclr/update/ycsconfirm",
                                        async: false,
                                        contentType: "application/json; charset=utf-8",
                                        data:JSON.stringify(ss3),
                                        dataType:"json",
                                        success:function (data) {
                                            message3 = data.message;
                                        },
                                        error:function (e) {
                                        }
                                    });
                                }

                                if($('select[name="cdopinion"] option:selected').val()!=""&&$('select[name="status"] option:selected').val()!=""&&$('select[name="inspopinion"] option:selected').val()!=""){
                                    var ss4 = new Object();
                                    ss4.inspnum = inspnum;
                                    ss4.inspdate = inspdate;
                                    ss4.inspopinion = $('select[name="inspopinion"] option:selected').val();
                                    ss4.opncontent = $('textarea[name="opncontent"]').val();
                                    ss4.rectopinion = $('textarea[name="rectopinion"]').val();
                                    ss4.rectresult = $('textarea[name="rectresult"]').val();
                                    ss4.rectnum = $('input[name="rectnum"]').val();
                                    ss4.ycs2 = $('input[name="ycs2"]').val();
                                    ss4.rq4 = $('input[name="rq4"]').val();
                                    ss4.ycs3 = $('input[name="ycs3"]').val();
                                    ss4.confirmresult = $('select[name="confirmresult"] option:selected').val();

                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/const/inspdclr/update/ycscheck",
                                        async: false,
                                        contentType: "application/json; charset=utf-8",
                                        data:JSON.stringify(ss4),
                                        dataType:"json",
                                        success:function (data) {
                                            message4 = data.message;
                                        },
                                        error:function (e) {
                                        }
                                    });
                                }

                                if(message2==""){
                                    if(message1 == "更新成功!"){
                                        layer.msg('建造检验报检单更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        layer.msg(message1, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }else if(message3==""){
                                    if(message1=="更新成功!"&&message2=="更新成功!"){
                                        layer.msg('建造检验报检单更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        if(message1 == "更新成功!"){
                                            message1 = "新建报检单模块 "+message1;
                                        }else{
                                            message1 = "<b style='color:red'>新建报检单模块 更新失败!<br>"+message1+"</b>";
                                        }
                                        if(message2 == "更新成功!"){
                                            message2 = "船东审核模块 "+message2;
                                        }else{
                                            message2 = "<b style='color:red'>船东审核模块 更新失败!<br>"+message2+"</b>";
                                        }
                                        layer.msg(message1+'<br><br>'+message2, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }else if(message4==""){
                                    if(message1=="更新成功!"&&message2=="更新成功!"&&message3=="更新成功!"){
                                        layer.msg('建造检验报检单更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        if(message1 == "更新成功!"){
                                            message1 = "新建报检单模块 "+message1;
                                        }else{
                                            message1 = "<b style='color:red'>新建报检单模块 更新失败!<br>"+message1+"</b>";
                                        }
                                        if(message2 == "更新成功!"){
                                            message2 = "船东审核模块 "+message2;
                                        }else{
                                            message2 = "<b style='color:red'>船东审核模块 更新失败!<br>"+message2+"</b>";
                                        }
                                        if(message3 == "更新成功!"){
                                            message3 = "验船师确认模块 "+message3;
                                        }else{
                                            message3 = "<b style='color:red'>验船师确认模块 更新失败!<br>"+message3+"</b>";
                                        }
                                        layer.msg(message1+'<br><br>'+message2+'<br><br>'+message3, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }else{
                                    console.log(message1+' '+message2+' '+message3+' '+message4);
                                    if(message1=="更新成功!"&&message2=="更新成功!"&&message3=="更新成功!"&&message4=="更新成功!"){
                                        layer.msg('建造检验报检单更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        if(message1 == "更新成功!"){
                                            message1 = "新建报检单模块 "+message1;
                                        }else{
                                            message1 = "<b style='color:red'>新建报检单模块 更新失败!<br>"+message1+"</b>";
                                        }
                                        if(message2 == "更新成功!"){
                                            message2 = "船东审核模块 "+message2;
                                        }else{
                                            message2 = "<b style='color:red'>船东审核模块 更新失败!<br>"+message2+"</b>";
                                        }
                                        if(message3 == "更新成功!"){
                                            message3 = "验船师确认模块 "+message3;
                                        }else{
                                            message3 = "<b style='color:red'>验船师确认模块 更新失败!<br>"+message3+"</b>";
                                        }
                                        if(message4 == "更新成功!"){
                                            message4 = "验船师审核模块 "+message3;
                                        }else{
                                            message4 = "<b style='color:red'>验船师审核模块 更新失败!<br>"+message4+"</b>";
                                        }
                                        layer.msg(message1+'<br><br>'+message2+'<br><br>'+message3+'<br><br>'+message4, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }

                            });

                        },
                        error:function (e) {
                        }
                    });

                },
                yes: function(index) {
                    console.log(index);
                },
                full: function(elem) {
                    var win = window.top === window.self ? window : parent.window;
                    $(win).on('resize', function() {
                        var $this = $(this);
                        elem.width($this.width()).height($this.height()).css({
                            top: 0,
                            left: 0
                        });
                        elem.children('div.layui-layer-content').height($this.height() - 95);
                    });
                }
            });
            form.render();
        });
    });

    $('body').on('click', '#closes', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });

    $('#search').on('click', function() {
        var type = $('#search_type').val();
        var value = $('#search_value').val();
        $('#s_type').attr("value",type);
        $('#s_value').attr("value",value);
        if( value === '' || value.length === 0) {
            layer.msg('请输入关键字！',{
                time:2000
            });
            return ;
        }

        paging.get({
            value: value,
            type: type
        });
    });

    $('#showall').on('click', function() {
        $('#search_type').val("");
        $('#search_value').val("");
        $('#s_type').removeAttr("value");
        $('#s_value').removeAttr("value");
        form.render();
        paging.get({
            value: null,
            type: null
        });
    });

    $('#add').on('click', function() {
        $.ajax({
            type: "GET",
            url: contextPath + "/project/const/" + inspnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                if(data.state=='禁用'){
                    layer.msg('该项目已被禁用',{
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else{
                    $.get('ConstNewCheckList.html?inspnum='+inspnum, null, function(ConstNewCheckList) {
                        layer.open({
                            type: 1,
                            title: '新建报检单',
                            content: ConstNewCheckList,
                            area: ['auto', '600px'],
                            maxmin: false,
                            success:function (layero,index) {
                                layero.find("#closex").on("click",function () {
                                    layer.closeAll();
                                });

                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/project/const/" + inspnum,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        $('input[name="shipname"]').attr("value",data.shipname);
                                        $('input[name="figurenum"]').attr("value",data.figurenum);
                                        $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                    },
                                    error:function (e) {
                                    }
                                });

                                $.ajax({
                                    type: "GET",
                                    url: contextPath + "/personal/info",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (data) {
                                        $('input[name="cc"]').attr("value",data.name);
                                    },
                                    error: function (e) {
                                    }
                                });

                                $('input[name="rq1"]').attr("value",getNowFormatDate());

                            },
                            yes: function(index) {
                                console.log(index);
                            },
                            full: function(elem) {
                                var win = window.top === window.self ? window : parent.window;
                                $(win).on('resize', function() {
                                    var $this = $(this);
                                    elem.width($this.width()).height($this.height()).css({
                                        top: 0,
                                        left: 0
                                    });
                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                });
                            }
                        });
                        form.render();
                    });
                }
            },
            error: function (e) {
            }
        });
    });

    exports('ConstCheckList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});